1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
'use client';
import { useState, useEffect } from 'react';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
interface SyncProgress {
tableName: string;
lastSyncDate: string;
currentPage: number;
totalProcessed: number;
status: 'running' | 'completed' | 'error' | 'skipped';
lastError?: string;
syncType: 'full' | 'delta' | 'rebuild';
startTime: number;
endTime?: number;
recordsSkipped?: number;
}
interface SyncConfig {
pageSize: number;
batchSize: number;
maxWorkers: number;
deltaSyncEnabled: boolean;
cronSchedule: string;
autoRefreshInterval: number;
environment: string;
}
export default function NONSAPSyncPage() {
const [syncProgress, setSyncProgress] = useState<SyncProgress[]>([]);
const [isLoading, setIsLoading] = useState(false);
const [lastUpdated, setLastUpdated] = useState<string>('');
const [syncConfig, setSyncConfig] = useState<SyncConfig | null>(null);
// 설정 정보 조회
const fetchSyncConfig = async () => {
try {
const response = await fetch('/api/nonsap-sync/config');
const result = await response.json();
if (result.success) {
setSyncConfig(result.data);
} else {
console.error('Failed to fetch sync config:', result.error);
}
} catch (error) {
console.error('Error fetching sync config:', error);
}
};
// 동기화 상태 조회
const fetchSyncStatus = async () => {
try {
const response = await fetch('/api/nonsap-sync/status');
const result = await response.json();
if (result.success) {
setSyncProgress(result.data);
setLastUpdated(result.timestamp);
} else {
console.error('Failed to fetch sync status:', result.error);
}
} catch (error) {
console.error('Error fetching sync status:', error);
}
};
// 수동 동기화 트리거
const triggerSync = async () => {
setIsLoading(true);
try {
const response = await fetch('/api/nonsap-sync/trigger', {
method: 'POST'
});
const result = await response.json();
if (result.success) {
// 상태 새로고침
setTimeout(fetchSyncStatus, 2000);
} else {
alert('동기화 시작에 실패했습니다: ' + result.error);
}
} catch (error) {
console.error('Error triggering sync:', error);
alert('동기화 트리거 중 오류가 발생했습니다.');
} finally {
setIsLoading(false);
}
};
// 상태별 배지 색상
const getStatusBadge = (status: string) => {
switch (status) {
case 'running':
return <Badge variant="default" className="bg-blue-500">실행 중</Badge>;
case 'completed':
return <Badge variant="default" className="bg-green-500">완료</Badge>;
case 'error':
return <Badge variant="destructive">오류</Badge>;
case 'skipped':
return <Badge variant="outline" className="bg-yellow-100">완료됨</Badge>;
default:
return <Badge variant="secondary">알 수 없음</Badge>;
}
};
// Cron 스케줄을 사용자 친화적으로 변환
const formatCronSchedule = (cronSchedule: string) => {
if (cronSchedule === '0 */30 * * * *') {
return '30분마다';
}
if (cronSchedule === '0 0 1 * * *') {
return '매일 새벽 1시';
}
return cronSchedule; // 기본값으로 원본 반환
};
// 동기화 타입별 배지 색상
const getSyncTypeBadge = (syncType: string) => {
switch (syncType) {
case 'delta':
return <Badge variant="default" className="bg-green-500">차분 동기화</Badge>;
case 'full':
return <Badge variant="default" className="bg-blue-500">전체 동기화</Badge>;
case 'rebuild':
return <Badge variant="default" className="bg-orange-500">삭제 후 재구성</Badge>;
default:
return <Badge variant="secondary">{syncType}</Badge>;
}
};
// 초기 데이터 로드
useEffect(() => {
fetchSyncConfig();
fetchSyncStatus();
}, []);
// 자동 새로고침
useEffect(() => {
if (!syncConfig) return;
const interval = setInterval(fetchSyncStatus, syncConfig.autoRefreshInterval);
return () => clearInterval(interval);
}, [syncConfig]);
return (
<div className="container mx-auto p-6">
<div className="flex justify-between items-center mb-6">
<div>
<h1 className="text-3xl font-bold">NONSAP 데이터 동기화</h1>
<p className="text-muted-foreground">
Oracle DB와 PostgreSQL 간의 데이터 동기화 상태를 모니터링합니다.
</p>
</div>
<div className="flex gap-2">
<Button onClick={fetchSyncStatus} variant="outline">
새로고침
</Button>
<Button onClick={triggerSync} disabled={isLoading}>
{isLoading ? '실행 중...' : '수동 동기화'}
</Button>
</div>
</div>
{lastUpdated && (
<Card className="mb-6">
<CardContent className="pt-6">
<p className="text-sm text-muted-foreground">
마지막 업데이트: {new Date(lastUpdated).toLocaleString('ko-KR')}
</p>
</CardContent>
</Card>
)}
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
{syncProgress.map((progress) => (
<Card key={progress.tableName}>
<CardHeader>
<div className="flex justify-between items-start">
<CardTitle className="text-lg">{progress.tableName}</CardTitle>
<div className="flex gap-2">
{getSyncTypeBadge(progress.syncType)}
{getStatusBadge(progress.status)}
</div>
</div>
<CardDescription>
마지막 동기화: {new Date(progress.lastSyncDate).toLocaleString('ko-KR')}
</CardDescription>
</CardHeader>
<CardContent>
<div className="space-y-2">
<div className="flex justify-between">
<span className="text-sm text-muted-foreground">현재 페이지:</span>
<span className="text-sm font-medium">{progress.currentPage}</span>
</div>
<div className="flex justify-between">
<span className="text-sm text-muted-foreground">처리된 레코드:</span>
<span className="text-sm font-medium">{progress.totalProcessed.toLocaleString()}</span>
</div>
{progress.recordsSkipped && progress.recordsSkipped > 0 && (
<div className="flex justify-between">
<span className="text-sm text-muted-foreground">스킵된 레코드:</span>
<span className="text-sm font-medium">{progress.recordsSkipped.toLocaleString()}</span>
</div>
)}
{progress.endTime && progress.startTime && (
<div className="flex justify-between">
<span className="text-sm text-muted-foreground">실행 시간:</span>
<span className="text-sm font-medium">
{((progress.endTime - progress.startTime) / 1000).toFixed(2)}초
</span>
</div>
)}
{progress.lastError && (
<div className="mt-2">
<p className="text-sm text-red-600 break-words">
오류: {progress.lastError}
</p>
</div>
)}
</div>
</CardContent>
</Card>
))}
</div>
{syncProgress.length === 0 && (
<Card>
<CardContent className="pt-6">
<p className="text-center text-muted-foreground">
동기화 정보가 없습니다. 동기화를 실행해보세요.
</p>
</CardContent>
</Card>
)}
{syncConfig && (
<Card className="mt-6">
<CardHeader>
<CardTitle>동기화 설정</CardTitle>
<CardDescription>
테이블별 최적 동기화 방식을 자동 선택하여 실행됩니다.
멀티스레드로 병렬 처리하여 성능을 최적화합니다.
</CardDescription>
</CardHeader>
<CardContent>
<div className="space-y-2 text-sm">
<p><strong>실행 환경:</strong> {syncConfig.environment}</p>
<p><strong>동기화 방식:</strong> 테이블별 자동 선택 (차분/전체/재구성)</p>
<p><strong>차분 동기화:</strong> {syncConfig.deltaSyncEnabled ? '활성화' : '비활성화'}</p>
<p><strong>실행 주기:</strong> {formatCronSchedule(syncConfig.cronSchedule)}</p>
<p><strong>페이지 크기:</strong> {syncConfig.pageSize.toLocaleString()}개 레코드</p>
<p><strong>배치 크기:</strong> {syncConfig.batchSize.toLocaleString()}개 레코드</p>
<p><strong>워커 수:</strong> {syncConfig.maxWorkers}개 (병렬 처리)</p>
<p><strong>자동 새로고침:</strong> {(syncConfig.autoRefreshInterval / 1000)}초마다</p>
<p><strong>동기화 대상:</strong> {syncProgress.length}개 테이블</p>
</div>
</CardContent>
</Card>
)}
</div>
);
}
|